package com.example.etwzgzxt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.etwzgzxt.R;
import com.example.etwzgzxt.bean.DeviceInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 创宇 on 2016/1/26.
 */
public class DeviceListAdapter extends BaseAdapter {


    private List<DeviceInfo> items = new ArrayList<>();
    private LayoutInflater inflater;

    public DeviceListAdapter(Context context, List<DeviceInfo> items) {
        this.inflater = inflater.from(context);
        this.items.addAll(items);
    }

    public void updateData(List<DeviceInfo> items) {
        this.items.clear();
        this.items.addAll(items);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return new Long(items.get(position).getId());
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        view = inflater.inflate(R.layout.item_device_list, null);
        ((TextView) view.findViewById(R.id.tvId)).setText((position+1)+"");
        ((TextView) view.findViewById(R.id.tvName)).setText(items.get(position).getName());
        ((TextView) view.findViewById(R.id.tvCode)).setText(items.get(position).getDeviceCode());
        ((TextView) view.findViewById(R.id.tvHolderName)).setText(items.get(position).getHolderName());
        return view;
    }
}
